package matlap.server;

import java.util.List;

import matlap.client.services.registration.RegService;
import matlap.database.dao.DAOFactory;
import matlap.database.dao.RegistrationDAO;
import matlap.shared.Student;
import matlap.shared.exceptions.MyException;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

/**
 * The server side implementation of the RPC service.
 */

@SuppressWarnings("serial")
public class RegServiceImpl extends RemoteServiceServlet implements RegService {

	DAOFactory df = DAOFactory.getInstance();
	RegistrationDAO rd = df.getRegistrationDAO();

	/**
	 * Inserts new people into people table, registered table and students
	 * table, by adding role, last name, first name, address, email, telephone
	 * number, school name and class, and turns back the username.
	 */

	public String insertPeople(int role, Student student) {
		return rd.insertPeople(role, student);
	}

	/**
	 * Inserts students into students table by adding username, school name and
	 * class.
	 */

	public void insertStudents(String userName, String schoolName, int classNr) {
		rd.insertStudents(userName, schoolName, classNr);
	}

	/**
	 * Turns back the schoolID from the school table by adding school name.
	 */

	public int selectSchoolID(String schoolName) {
		return rd.selectSchoolID(schoolName);
	}

	/**
	 * Inserts people to registered table, who exists in the people table, by
	 * adding last name, first name, email, tel and address.
	 * 
	 * @return
	 */

	// public String insertIntoRegistered(Student student){
	// return rd.insertIntoRegistered(student);

	// }

	/**
	 * Inserts people into people table by adding role, last name, first name
	 * and address.
	 * @throws MyException 
	 */

	@Override
	public void insertInPeople(int role, String lastName, String firstName,
			String address) throws MyException {

		rd.insertInPeople(role, lastName, firstName, address);
	}

	/**
	 * Inserts students into people table by adding
	 * @throws MyException 
	 */

	@Override
	public void insertStudentsPeople(String lastName, String firstName,
			String address, String schoolName, int classNr) throws MyException {

		rd.insertStudentsPeople(lastName, firstName, address, schoolName,
				classNr);
	}

	@Override
	public String insertIntoRegistered(Student student) {
		// TODO Auto-generated method stub
		return rd.insertIntoRegistered(student);
	}

	@Override
	public void updatePassword(String username, String p) {
		rd.updatePassword(username, p);
	}

	@Override
	public void updateContact(String username, String email, String phone,
			String address) {
		rd.updateContact(username, email, phone, address);
	}

	@Override
	public void updatePeople(String username, String last_name,
			String first_name, String address) {
		rd.updatePeople(username, last_name, first_name, address);

	}

	@Override
	public List<String> getRegNames() {
		return rd.getRegNames();
	}
}
